package com.huawei.appmarket.service.thirdappdl;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.DialogInterface.OnKeyListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.NetworkInfo;
import android.net.NetworkInfo.State;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import com.huawei.appgallery.packagemanager.api.bean.ManagerTask;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appgallery.updatemanager.api.UpgradeResponse;
import com.huawei.appmarket.framework.activity.SecureActivity;
import com.huawei.appmarket.service.thirdappdl.ThirdAppDownloadActivityProtocol.Request;
import com.huawei.hms.support.api.entity.hwid.HwIDConstant.ACTION;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import com.huawei.updatesdk.service.otaupdate.UpdateStatusCode.DialogButton;
import java.lang.ref.WeakReference;
import java.text.DecimalFormat;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import o.BaseRequest;
import o.dgh;
import o.dgm;
import o.djl;
import o.djy;
import o.dkb;
import o.dkc;
import o.Logger;
import o.dof;
import o.doo;
import o.ContentManager;
import o.dss;
import o.dvr;
import o.dvt;
import o.dwb;
import o.dwl;
import o.ejk;
import o.ejr;
import o.ejs;
import o.epr;
import o.epv;
import o.CollectCheck;
import o.erz;
import o.ActivityUtil;
import o.MinimumFactory;
import o.evk;
import o.ewb;
import o.ewm.n;

@SuppressLint({"InflateParams"})
@TargetApi(17)
public class ThirdAppDownloadActivity extends SecureActivity<ThirdAppDownloadActivityProtocol> implements ejs, OnClickListener {
    private static int ˋˋ;
    private AlertDialog ʻॱ;
    private String ʼॱ = "";
    private boolean ʽॱ = false;
    private TextView ʾ;
    private ProgressBar ʿ;
    private TextView ˈ;
    private String ˉ = "";
    private String ˊˊ = "";
    private int ˊˋ = 1;
    protected String ˊॱ = "";
    private int ˊᐝ = -1;
    private int ˋˊ;
    protected String ˋॱ = "";
    private boolean ˋᐝ = false;
    private ejk ˌ;
    private boolean ˍ = false;
    private boolean ˎˎ = true;
    private AlertDialog ˏॱ;
    private final BroadcastReceiver ˑ = new BroadcastReceiver(this) {
        final /* synthetic */ ThirdAppDownloadActivity ˊ;

        {
            this.ˊ = r1;
        }

        public void onReceive(Context context, Intent intent) {
            this.ˊ.ˏ(601);
            this.ˊ.finish();
        }
    };
    private AlertDialog ͺ;
    protected int ॱˊ = 0;
    private djl ॱˋ;
    private AlertDialog ॱˎ;
    private AlertDialog ॱᐝ;
    private g ᐝॱ = new g(this);

    static abstract class d implements OnKeyListener {
        abstract void ˏ(DialogInterface dialogInterface);

        private d() {
        }

        public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
            if (i != 4 || keyEvent.getAction() != 0) {
                return false;
            }
            ˏ(dialogInterface);
            return true;
        }
    }

    class a implements IServerCallBack {
        private WeakReference<ThirdAppDownloadActivity> ˎ;
        final /* synthetic */ ThirdAppDownloadActivity ॱ;

        public a(ThirdAppDownloadActivity thirdAppDownloadActivity, ThirdAppDownloadActivity thirdAppDownloadActivity2) {
            this.ॱ = thirdAppDownloadActivity;
            this.ˎ = new WeakReference(thirdAppDownloadActivity2);
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        private void ˊ() {
            this.ॱ.ˏ(402);
        }

        private void ˏ() {
            this.ॱ.ˏ(401);
        }

        private boolean ˋ() {
            if (this.ˎ == null || ActivityUtil.isAcitivtyNotValid((Context) this.ˎ.get())) {
                return false;
            }
            if (this.ॱ.ʽॱ) {
                Logger.ˏ("ThirdAppDownloadActivity", "loading dialog is canceled");
                return false;
            }
            if (this.ॱ.ॱˋ != null && this.ॱ.ॱˋ.isShowing()) {
                this.ॱ.ॱˋ.dismiss();
            }
            if (this.ॱ.ᐝॱ.hasMessages(2019121801)) {
                Logger.ˏ("ThirdAppDownloadActivity", "result is back, will not show loading dialog");
                this.ॱ.ᐝॱ.removeMessages(2019121801);
            }
            return true;
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            if (ˋ()) {
                UpgradeResponse upgradeResponse = (UpgradeResponse) responseBean;
                if (responseBean instanceof UpgradeResponse) {
                    if (3 == responseBean.getResponseCode()) {
                        ˏ();
                        evk.ˋ(this.ॱ, this.ॱ.getString(n.ʹˊ), 0).ˋ();
                        this.ॱ.finish();
                    } else if (responseBean.getResponseCode() != 0) {
                        ˏ();
                        evk.ˋ(this.ॱ, this.ॱ.getString(n.ॱˉ), 0).ˋ();
                        this.ॱ.finish();
                    } else if (CollectCheck.isEmpty(upgradeResponse.ॱ())) {
                        ˏ();
                        evk.ˋ(this.ॱ, this.ॱ.getString(n.ˊꜟ), 0).ˋ();
                        this.ॱ.finish();
                    } else {
                        ApkUpgradeInfo ˊ = ˊ(this.ॱ.ˊॱ, upgradeResponse.ॱ());
                        if (ˊ != null) {
                            if (!this.ॱ.ˍ || this.ॱ.ॱˊ == 0 || this.ॱ.ॱˊ <= ˊ.ʿ()) {
                                ˎ(ˊ);
                                return;
                            } else {
                                ॱ();
                                return;
                            }
                        }
                    }
                }
                this.ॱ.finish();
            }
        }

        private void ॱ() {
            ˊ();
            this.ॱ.finish();
        }

        private void ˎ(ApkUpgradeInfo apkUpgradeInfo) {
            if (dvr.ˏ(ContentManager.getInstant().getContext(), true)) {
                this.ॱ.ˊˋ();
                int ˎ = dgm.ˎ(this.ॱ);
                djy.ˋ(3, new c(this.ॱ));
                ejr.ˏ().ˊ(apkUpgradeInfo, djy.class, false, ˎ, true, 3);
                return;
            }
            this.ॱ.ˏ(apkUpgradeInfo);
        }

        private ApkUpgradeInfo ˊ(String str, List<ApkUpgradeInfo> list) {
            if (CollectCheck.isEmpty(list)) {
                return null;
            }
            for (ApkUpgradeInfo apkUpgradeInfo : list) {
                if (apkUpgradeInfo.ᐝ().equals(str)) {
                    break;
                }
            }
            ApkUpgradeInfo apkUpgradeInfo2 = null;
            return apkUpgradeInfo2;
        }
    }

    final class b implements o.ckh.e {
        final /* synthetic */ ThirdAppDownloadActivity ˊ;
        private BroadcastReceiver ॱ;

        public b(ThirdAppDownloadActivity thirdAppDownloadActivity) {
            this.ˊ = thirdAppDownloadActivity;
        }

        public void ॱ(Activity activity) {
            this.ॱ = new j(this.ˊ, activity);
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction("android.net.wifi.STATE_CHANGE");
            activity.registerReceiver(this.ॱ, intentFilter);
        }

        public void ˋ(Activity activity) {
            if (this.ॱ != null) {
                activity.unregisterReceiver(this.ॱ);
            }
        }
    }

    static class c implements dkc {
        WeakReference<ThirdAppDownloadActivity> ˋ;

        public c(ThirdAppDownloadActivity thirdAppDownloadActivity) {
            this.ˋ = new WeakReference(thirdAppDownloadActivity);
        }

        public void ॱ(SessionDownloadTask sessionDownloadTask) {
            ˋ(sessionDownloadTask);
        }

        private void ˋ(SessionDownloadTask sessionDownloadTask) {
            ThirdAppDownloadActivity thirdAppDownloadActivity = (ThirdAppDownloadActivity) this.ˋ.get();
            if (thirdAppDownloadActivity == null) {
                Logger.e("ThirdAppDownloadActivity", "appDownloadActivity is null");
            } else if (thirdAppDownloadActivity.ʿ == null || thirdAppDownloadActivity.ʾ == null || thirdAppDownloadActivity.ˈ == null) {
                Logger.e("ThirdAppDownloadActivity", "downloadProgressbar or downloadText or downloadSizeText is null!");
            } else {
                ˋ(sessionDownloadTask, thirdAppDownloadActivity);
            }
        }

        private void ˋ(SessionDownloadTask sessionDownloadTask, ThirdAppDownloadActivity thirdAppDownloadActivity) {
            switch (sessionDownloadTask.ˈ()) {
                case 1:
                case 2:
                    ˏ(sessionDownloadTask);
                    return;
                case 4:
                    if (thirdAppDownloadActivity.ʿ != null) {
                        thirdAppDownloadActivity.ʿ.setProgress(100);
                    }
                    thirdAppDownloadActivity.ˈ.setText(thirdAppDownloadActivity.ˏ(sessionDownloadTask.ˋˊ()) + "/" + thirdAppDownloadActivity.ˏ(dkb.ˏ(sessionDownloadTask)));
                    ejr.ˏ().ˋ(sessionDownloadTask, thirdAppDownloadActivity);
                    djy.ॱ(3);
                    return;
                case 5:
                    thirdAppDownloadActivity.ˎ(true);
                    djy.ॱ(3);
                    return;
                case 6:
                    if (sessionDownloadTask.ˏˎ()) {
                        thirdAppDownloadActivity.ˎ(false);
                        return;
                    } else if (sessionDownloadTask.ᐝॱ() == 2) {
                        thirdAppDownloadActivity.ˏ(501);
                        if (thirdAppDownloadActivity.ʽॱ()) {
                            thirdAppDownloadActivity.ˊ(true);
                            return;
                        } else if (thirdAppDownloadActivity.ʻॱ()) {
                            evk.ˋ(thirdAppDownloadActivity, thirdAppDownloadActivity.getString(n.ˊॱ), 0).ˋ();
                            thirdAppDownloadActivity.finish();
                            return;
                        } else {
                            return;
                        }
                    } else {
                        return;
                    }
                case 7:
                    return;
                default:
                    Logger.e("ThirdAppDownloadActivity", "Unkonw message " + sessionDownloadTask.ˈ() + " ,taskid:" + sessionDownloadTask.ʾ());
                    return;
            }
        }

        private void ˏ(SessionDownloadTask sessionDownloadTask) {
            ThirdAppDownloadActivity thirdAppDownloadActivity = (ThirdAppDownloadActivity) this.ˋ.get();
            if (thirdAppDownloadActivity == null) {
                Logger.e("ThirdAppDownloadActivity", "appDownloadActivity is null");
            } else if (thirdAppDownloadActivity.ʿ == null) {
                Logger.e("ThirdAppDownloadActivity", "downloadProgressbar is null");
            } else {
                long ˋˊ = sessionDownloadTask.ˋˊ();
                float progress = ((float) thirdAppDownloadActivity.ʿ.getProgress()) / ((float) thirdAppDownloadActivity.ʿ.getMax());
                thirdAppDownloadActivity.ʿ.setMax(100);
                thirdAppDownloadActivity.ʿ.setProgress(sessionDownloadTask.ʼॱ());
                thirdAppDownloadActivity.ʾ.setText(MinimumFactory.setMinimumFt((int) (progress * 100.0f)));
                thirdAppDownloadActivity.ˈ.setText(thirdAppDownloadActivity.ˏ(ˋˊ) + "/" + thirdAppDownloadActivity.ˏ(dkb.ˏ(sessionDownloadTask)));
            }
        }
    }

    static class e implements OnDismissListener {
        private dwl ˊ;

        public e(dwl o_dwl) {
            this.ˊ = o_dwl;
        }

        public void onDismiss(DialogInterface dialogInterface) {
            dialogInterface.dismiss();
            if (this.ˊ != null && this.ˊ.ॱ() != null) {
                this.ˊ.ॱ().ॱ();
            }
        }
    }

    static class f implements o.dkb.d {
        private f() {
        }

        public void ˋ(SessionDownloadTask sessionDownloadTask) {
            if (sessionDownloadTask != null) {
                dvt.ˏ().ॱ(sessionDownloadTask);
            }
        }
    }

    static class g extends Handler {
        private WeakReference<ThirdAppDownloadActivity> ˎ;

        public g(ThirdAppDownloadActivity thirdAppDownloadActivity) {
            this.ˎ = new WeakReference(thirdAppDownloadActivity);
        }

        public void handleMessage(@NonNull Message message) {
            super.handleMessage(message);
            if (message.what == 2019121801 && this.ˎ != null && this.ˎ.get() != null) {
                ((ThirdAppDownloadActivity) this.ˎ.get()).ˍ();
            }
        }
    }

    final class h implements o.ckh.a {
        final /* synthetic */ ThirdAppDownloadActivity ˎ;
        private ApkUpgradeInfo ॱ;

        public h(ThirdAppDownloadActivity thirdAppDownloadActivity, ApkUpgradeInfo apkUpgradeInfo) {
            this.ˎ = thirdAppDownloadActivity;
            this.ॱ = apkUpgradeInfo;
        }

        public void ˏ(AlertDialog alertDialog, com.huawei.appgallery.foundation.ui.framework.widget.dialog.dialogactivity.DialogActivity.a aVar, int i) {
            if (aVar.ˏ() == null) {
                Logger.e("ThirdAppDownloadActivity", "view is null");
            } else if (-1 == i) {
                dvr.ॱ(aVar.ˏ(), true);
                this.ˎ.ˊˋ();
                int ˎ = dgm.ˎ(this.ˎ);
                djy.ˋ(3, new c(this.ˎ));
                ejr.ˏ().ˊ(this.ॱ, djy.class, false, ˎ, true, 3);
            } else if (-2 == i) {
                dvr.ॱ(aVar.ˏ(), false);
                this.ˎ.ˎ(this.ॱ);
                this.ˎ.finish();
            }
        }
    }

    class i implements OnKeyListener {
        final /* synthetic */ ThirdAppDownloadActivity ॱ;

        private i(ThirdAppDownloadActivity thirdAppDownloadActivity) {
            this.ॱ = thirdAppDownloadActivity;
        }

        public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
            if (i != 4 || keyEvent.getAction() != 0) {
                return false;
            }
            dialogInterface.dismiss();
            this.ॱ.finish();
            return true;
        }
    }

    final class j extends SafeBroadcastReceiver {
        final /* synthetic */ ThirdAppDownloadActivity ˊ;
        private final WeakReference<Activity> ˏ;

        public j(ThirdAppDownloadActivity thirdAppDownloadActivity, Activity activity) {
            this.ˊ = thirdAppDownloadActivity;
            this.ˏ = new WeakReference(activity);
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if ("android.net.wifi.STATE_CHANGE".equals(intent.getAction())) {
                NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra("networkInfo");
                if (networkInfo != null && State.CONNECTED == networkInfo.getState()) {
                    int ॱ = dvt.ॱ(context);
                    if (ॱ == 0 || ThirdAppDownloadActivity.ˋˋ == ॱ) {
                        Logger.ˎ("ThirdAppDownloadActivity", "Keep current download dialog");
                        return;
                    }
                    Logger.ˎ("ThirdAppDownloadActivity", "network has changed,close the download dialog, lastNetType=" + ThirdAppDownloadActivity.ˋˋ + " newNetType=" + ॱ);
                    Activity activity = (Activity) this.ˏ.get();
                    if (activity != null) {
                        activity.finish();
                    }
                    this.ˊ.finish();
                }
            }
        }
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.intent.action.LOCALE_CHANGED");
        registerReceiver(this.ˑ, intentFilter);
        ThirdAppDownloadActivityProtocol thirdAppDownloadActivityProtocol = (ThirdAppDownloadActivityProtocol) ʾ();
        if (thirdAppDownloadActivityProtocol == null || thirdAppDownloadActivityProtocol.ˊ() == null) {
            Logger.ˋ("ThirdAppDownloadActivity", "error,protocol or request is null.");
            finish();
            return;
        }
        Request ˊ = thirdAppDownloadActivityProtocol.ˊ();
        this.ˊॱ = ˊ.ॱ();
        this.ˋॱ = ˊ.ˊ();
        this.ˊˊ = ˊ.ˏ();
        this.ˊˋ = ˊ.ʽ();
        this.ˋˊ = ˊ.ॱॱ();
        this.ˉ = ˊ.ʼ();
        this.ˋᐝ = ˊ.ͺ();
        this.ˍ = ˊ.ˏॱ();
        this.ʼॱ = ˊ.ˊॱ();
        this.ˎˎ = ˊ.ॱˋ();
        this.ॱˊ = thirdAppDownloadActivityProtocol.ˊ().ʻ();
        this.ˊᐝ = thirdAppDownloadActivityProtocol.ˊ().ˋॱ();
        ᐝ();
        if (TextUtils.isEmpty(this.ˊॱ)) {
            Logger.ˋ("ThirdAppDownloadActivity", "error:mPackageName is null");
            return;
        }
        ˈ();
        ͺ();
    }

    public void onDestroy() {
        super.onDestroy();
        unregisterReceiver(this.ˑ);
    }

    protected void ˏ(ejk o_ejk) {
        this.ˌ = o_ejk;
    }

    protected void ᐝ() {
    }

    private void ˈ() {
        if (!TextUtils.isEmpty(this.ʼॱ) && TextUtils.isEmpty(this.ˊˊ)) {
            if (this.ˍ) {
                this.ˊˊ = getString(n.ՙˊ, new Object[]{this.ʼॱ});
                return;
            }
            this.ˊˊ = getString(n.ˋﾞ, new Object[]{this.ʼॱ});
        }
    }

    protected int ॱˋ() {
        if (this.ˊᐝ == 1) {
            return n.ﹶ;
        }
        if (this.ˊᐝ == 0) {
            return n.ٴ;
        }
        if (this.ˍ) {
            return n.ﹶ;
        }
        return n.ٴ;
    }

    protected boolean ʻॱ() {
        return true;
    }

    protected boolean ʽॱ() {
        return false;
    }

    protected int ʿ() {
        return n.ˊˈ;
    }

    protected int ᐝॱ() {
        return o.ewm.h.ˉˋ;
    }

    protected boolean ॱˎ() {
        return true;
    }

    private boolean ˉ() {
        if (!this.ˍ) {
            return true;
        }
        int ˎ = erz.ˎ(this, this.ˊॱ);
        if (ˎ == -1 || ˎ == 0 || ˎ < this.ॱˊ) {
            return true;
        }
        Logger.ˎ("ThirdAppDownloadActivity", "no need to update, the package is " + this.ˊॱ);
        ˏ(403);
        return false;
    }

    protected void ॱˊ() {
        ˏ((int) DialogButton.CONFIRM);
        if (!ॱˎ()) {
            return;
        }
        if (!ˉ()) {
            finish();
        } else if (doo.ˊ(this)) {
            this.ͺ.dismiss();
            ˏ(this.ˊॱ);
        } else {
            ˏ(502);
            evk.ˋ(this, getString(n.ʹˊ), 0).ˋ();
            finish();
        }
    }

    protected void ˊॱ() {
        ˏ(102);
        this.ͺ.dismiss();
        finish();
    }

    protected boolean ʼ() {
        return this.ˋᐝ;
    }

    public void ˊ(String str) {
        this.ˊˊ = str;
    }

    public void ˎ(String str) {
        this.ˊॱ = str;
    }

    protected void ͺ() {
        if (isFinishing()) {
            Logger.ˎ("ThirdAppDownloadActivity", "activity is finishing, can not show inquire dialog");
            return;
        }
        Builder builder = new Builder(this);
        if (ʼ()) {
            builder.setTitle(n.ˋٴ);
        }
        builder.setMessage(this.ˊˊ);
        builder.setPositiveButton(ॱˋ(), new DialogInterface.OnClickListener(this) {
            final /* synthetic */ ThirdAppDownloadActivity ˏ;

            {
                this.ˏ = r1;
            }

            public void onClick(DialogInterface dialogInterface, int i) {
                this.ˏ.ॱˊ();
            }
        });
        builder.setNegativeButton(ʿ(), new DialogInterface.OnClickListener(this) {
            final /* synthetic */ ThirdAppDownloadActivity ˏ;

            {
                this.ˏ = r1;
            }

            public void onClick(DialogInterface dialogInterface, int i) {
                this.ˏ.ˊॱ();
            }
        });
        this.ͺ = builder.create();
        this.ͺ.setOnKeyListener(new d(this) {
            final /* synthetic */ ThirdAppDownloadActivity ˋ;

            {
                this.ˋ = r2;
            }

            void ˏ(DialogInterface dialogInterface) {
                Logger.ˎ("ThirdAppDownloadActivity", "click key back, use flow dialog dismiss.");
                this.ˋ.ˊॱ();
            }
        });
        this.ͺ.setCanceledOnTouchOutside(false);
        this.ͺ.show();
        ˏ(100);
        ewb.ˊ(this.ͺ);
    }

    private void ˏ(int i) {
        if (this.ˌ != null) {
            this.ˌ.ˊ(i);
        }
    }

    private void ˊˋ() {
        if (isFinishing()) {
            Logger.ˎ("ThirdAppDownloadActivity", "activity is finishing, can not show progress dialog");
        } else if (this.ˏॱ == null) {
            this.ˏॱ = new Builder(this).create();
            View inflate = LayoutInflater.from(this).inflate(ᐝॱ(), null);
            this.ʿ = (ProgressBar) inflate.findViewById(o.ewm.j.ʿꓸ);
            this.ʾ = (TextView) inflate.findViewById(o.ewm.j.ʿᶥ);
            this.ˈ = (TextView) inflate.findViewById(o.ewm.j.ʿꜞ);
            inflate.findViewById(o.ewm.j.ꜝ).setOnClickListener(this);
            int ˋ = epv.ˋ(this, 16);
            this.ˏॱ.setView(inflate, ˋ, 0, ˋ, 0);
            this.ˏॱ.setOnKeyListener(new d(this) {
                final /* synthetic */ ThirdAppDownloadActivity ॱ;

                {
                    this.ॱ = r2;
                }

                void ˏ(DialogInterface dialogInterface) {
                    Logger.ˎ("ThirdAppDownloadActivity", "click key back, down dialog dismiss.");
                    this.ॱ.ˋˊ();
                }
            });
            this.ˏॱ.setCanceledOnTouchOutside(false);
            this.ˏॱ.show();
            this.ʾ.setText("0%");
            this.ˈ.setText(getString(n.ˊﹶ));
        }
    }

    private void ˋˊ() {
        if (isFinishing()) {
            Logger.ˎ("ThirdAppDownloadActivity", "activity is finishing, can not show cancel download dialog");
        } else if (this.ˏॱ != null && this.ˏॱ.isShowing()) {
            Builder builder = new Builder(this);
            builder.setMessage(n.ˊᵢ);
            builder.setPositiveButton(n.ˋՙ, new DialogInterface.OnClickListener(this) {
                final /* synthetic */ ThirdAppDownloadActivity ˋ;

                {
                    this.ˋ = r1;
                }

                public void onClick(DialogInterface dialogInterface, int i) {
                    if (!(this.ˋ.ʿ == null || this.ˋ.ʾ == null)) {
                        this.ˋ.ʿ.setProgress(0);
                        this.ˋ.ʿ.setMax(0);
                        this.ˋ.ʾ.setText("");
                    }
                    this.ˋ.ˏॱ.dismiss();
                    this.ˋ.ॱᐝ.dismiss();
                    ejr.ˏ().ˎ();
                    this.ˋ.ˏ(202);
                    this.ˋ.finish();
                }
            });
            builder.setNegativeButton(n.ˊˈ, new DialogInterface.OnClickListener(this) {
                final /* synthetic */ ThirdAppDownloadActivity ˋ;

                {
                    this.ˋ = r1;
                }

                public void onClick(DialogInterface dialogInterface, int i) {
                    this.ˋ.ॱᐝ.dismiss();
                }
            });
            this.ॱᐝ = builder.create();
            this.ॱᐝ.setOnKeyListener(new d(this) {
                final /* synthetic */ ThirdAppDownloadActivity ˏ;

                {
                    this.ˏ = r2;
                }

                void ˏ(DialogInterface dialogInterface) {
                    this.ˏ.ॱᐝ.dismiss();
                }
            });
            this.ॱᐝ.setCanceledOnTouchOutside(false);
            this.ॱᐝ.show();
            ewb.ˊ(this.ॱᐝ);
        }
    }

    private void ˊ(boolean z) {
        if (isFinishing()) {
            Logger.ˎ("ThirdAppDownloadActivity", "activity is finishing, can not show download failed dialog");
            return;
        }
        Builder builder = new Builder(this);
        if (z) {
            builder.setMessage(n.ˋʹ);
        } else {
            builder.setMessage(n.ˊꜝ);
        }
        builder.setPositiveButton(n.ˋʾ, new DialogInterface.OnClickListener(this) {
            final /* synthetic */ ThirdAppDownloadActivity ॱ;

            {
                this.ॱ = r1;
            }

            public void onClick(DialogInterface dialogInterface, int i) {
                this.ॱ.ˊˊ();
            }
        });
        this.ʻॱ = builder.create();
        this.ʻॱ.setCancelable(false);
        this.ʻॱ.setOnKeyListener(new d(this) {
            final /* synthetic */ ThirdAppDownloadActivity ˊ;

            {
                this.ˊ = r2;
            }

            void ˏ(DialogInterface dialogInterface) {
                Logger.ˎ("ThirdAppDownloadActivity", "click key back, download fail dialog dismiss.");
                this.ˊ.ˊˊ();
                this.ˊ.ʻॱ.dismiss();
            }
        });
        this.ʻॱ.setCanceledOnTouchOutside(false);
        this.ʻॱ.show();
        ˏ(201);
        ewb.ˊ(this.ʻॱ);
    }

    private void ˊᐝ() {
        if (isFinishing()) {
            Logger.ˎ("ThirdAppDownloadActivity", "activity is finishing, can not show install failed dialog");
            return;
        }
        Builder builder = new Builder(this);
        builder.setMessage(n.ꜟᐝ);
        builder.setPositiveButton(n.ˋʾ, new DialogInterface.OnClickListener(this) {
            final /* synthetic */ ThirdAppDownloadActivity ˋ;

            {
                this.ˋ = r1;
            }

            public void onClick(DialogInterface dialogInterface, int i) {
                this.ˋ.finish();
            }
        });
        this.ॱˎ = builder.create();
        this.ॱˎ.setOnKeyListener(new d(this) {
            final /* synthetic */ ThirdAppDownloadActivity ˊ;

            {
                this.ˊ = r2;
            }

            void ˏ(DialogInterface dialogInterface) {
                Logger.ˎ("ThirdAppDownloadActivity", "click key back, install fail dialog dismiss.");
                this.ˊ.ॱˎ.dismiss();
                this.ˊ.finish();
            }
        });
        this.ॱˎ.setCanceledOnTouchOutside(false);
        this.ॱˎ.show();
        ˏ(301);
        ewb.ˊ(this.ॱˎ);
    }

    private void ˊˊ() {
        if (this.ʿ != null) {
            this.ʿ.setProgress(0);
            this.ʿ.setMax(0);
        }
        try {
            if (this.ˏॱ != null) {
                this.ˏॱ.dismiss();
            }
        } catch (IllegalArgumentException e) {
            if (Logger.ˎ()) {
                Logger.ˏ("ThirdAppDownloadActivity", "dlProgressDialog dismiss IllegalArgumentException");
            }
        }
        this.ʻॱ.dismiss();
        ejr.ˏ().ˊ();
        finish();
    }

    public void onClick(View view) {
        if (view.getId() == o.ewm.j.ꜝ && this.ˏॱ != null && this.ˏॱ.isShowing()) {
            Logger.ˎ("ThirdAppDownloadActivity", "click key back, down dialog dismiss.");
            ˋˊ();
        }
    }

    public void ˏ(String str) {
        if (this.ˎˎ) {
            dss.ॱ().ˏ(getApplicationContext(), str, new a(this, this), 1);
        } else {
            dss.ॱ().ˏ(getApplicationContext(), str, new a(this, this), 2);
        }
        this.ᐝॱ.sendEmptyMessageDelayed(2019121801, 500);
    }

    private void ˎ(boolean z) {
        if (z) {
            ejr.ˏ().ˎ();
        }
        if (!ActivityUtil.isAcitivtyNotValid(this)) {
            if (ʻॱ()) {
                evk.ˋ(this, getString(n.ˊॱ), 0).ˋ();
            }
            try {
                this.ˏॱ.dismiss();
            } catch (IllegalArgumentException e) {
                if (Logger.ˎ()) {
                    Logger.ˏ("ThirdAppDownloadActivity", "dlProgressDialog dismiss IllegalArgumentException");
                }
            }
            if (ʽॱ()) {
                ˊ(false);
            } else {
                ˏ(201);
                ejr.ˏ().ˊ();
                finish();
            }
            Logger.ˎ("ThirdAppDownloadActivity", "download activity on download failed.");
        }
    }

    public void ॱ(String str) {
    }

    public void ˋ(String str) {
        ˏ(302);
        if (!ActivityUtil.isAcitivtyNotValid(this)) {
            if (this.ˏॱ != null) {
                try {
                    this.ˏॱ.dismiss();
                } catch (IllegalArgumentException e) {
                    if (Logger.ˎ()) {
                        Logger.ˏ("ThirdAppDownloadActivity", "dlProgressDialog dismiss IllegalArgumentException");
                    }
                }
            }
            if (this.ॱᐝ != null) {
                try {
                    this.ॱᐝ.dismiss();
                } catch (IllegalArgumentException e2) {
                    if (Logger.ˎ()) {
                        Logger.ˏ("ThirdAppDownloadActivity", "dlCancelDialog dismiss IllegalArgumentException");
                    }
                }
            }
            if (this.ͺ != null) {
                try {
                    this.ͺ.dismiss();
                } catch (IllegalArgumentException e3) {
                    if (Logger.ˎ()) {
                        Logger.ˏ("ThirdAppDownloadActivity", "dlInquireDialog dismiss IllegalArgumentException");
                    }
                }
            }
            ejr.ˏ().ˊ();
            ॱॱ();
        }
    }

    protected void ॱॱ() {
        if (!dof.ॱ(this.ˋॱ)) {
            try {
                Uri parse = Uri.parse(this.ˋॱ);
                startActivity(new Intent(ACTION.HWID_SCHEME_URL, parse));
                if (Logger.ˎ()) {
                    Logger.ˏ("ThirdAppDownloadActivity", "url link:" + parse);
                }
            } catch (Exception e) {
                if (Logger.ˎ()) {
                    Logger.ˏ("ThirdAppDownloadActivity", e.toString());
                }
            }
            ˋˋ();
        }
        finish();
    }

    private void ˋˋ() {
        if (this.ˊˋ == 1) {
            dgh.onEvent(new o.dge.d(ContentManager.getInstant().getContext(), n.ꜟ).ˏ(this.ˋˊ + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ˉ).ˋ());
        } else if (this.ˊˋ == 2) {
            dgh.onEvent(new o.dge.d(this, n.ꓸ).ˏ(this.ˋˊ + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ˉ).ˋ());
        }
    }

    public void ˏ(String str, int i) {
        Logger.ˎ("ThirdAppDownloadActivity", "install failed.");
        if (ʻॱ()) {
            evk.ˋ(this, getString(n.ˊⁱ), 0).ˋ();
        }
        if (this.ˏॱ != null) {
            this.ˏॱ.dismiss();
        }
        if (ʽॱ()) {
            ˊᐝ();
            return;
        }
        ejr.ˏ().ˊ();
        finish();
    }

    private String ˏ(long j) {
        DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
        decimalFormat.applyPattern("#.##");
        return decimalFormat.format((((double) j) / 1024.0d) / 1024.0d) + "MB";
    }

    public void ॱ(ManagerTask managerTask) {
        ˏ(301);
    }

    public void onResume() {
        super.onResume();
        dgh.ˏ(getClass().getCanonicalName(), ˋᐝ());
    }

    public void onPause() {
        super.onPause();
        dgh.ॱ(getClass().getCanonicalName(), ˋᐝ());
    }

    private LinkedHashMap ˋᐝ() {
        LinkedHashMap linkedHashMap = new LinkedHashMap(3);
        if (epr.ˎ().ˏ() != null) {
            linkedHashMap.put("third_id", epr.ˎ().ˏ());
        }
        if (!dof.ॱ(this.ˋॱ)) {
            linkedHashMap.put("page_id", this.ˋॱ);
        }
        linkedHashMap.put("service_type", Integer.valueOf(dgm.ˎ(this)));
        return linkedHashMap;
    }

    private void ˎ(ApkUpgradeInfo apkUpgradeInfo) {
        dwb.ˋ(apkUpgradeInfo.ˊ());
        SessionDownloadTask ˋ = dvt.ˏ().ˋ(apkUpgradeInfo.ᐝ());
        if (ˋ == null) {
            ejr.ˏ().ˎ(apkUpgradeInfo, new f());
        } else {
            dvt.ˏ().ॱ(ˋ);
        }
    }

    private void ˏ(ApkUpgradeInfo apkUpgradeInfo) {
        long ʼ;
        if (apkUpgradeInfo.ʼ() > 0) {
            ʼ = apkUpgradeInfo.ʼ();
        } else {
            ʼ = apkUpgradeInfo.ʻॱ();
        }
        Context ˋ = ContentManager.getInstant().getContext();
        dwl o_dwl = new dwl();
        o.ckh.a hVar = new h(this, apkUpgradeInfo);
        OnDismissListener eVar = new e(o_dwl);
        o.ckh.e bVar = new b(this);
        OnKeyListener iVar = new i();
        if (dvr.ˏ(ˋ)) {
            ˋˋ = 1;
            dvr.ˏ(ˋ, ʼ, hVar, eVar, bVar, iVar);
        } else if (dvr.ॱ(ˋ)) {
            ˎ(apkUpgradeInfo);
            finish();
        } else if (dvr.ˋ(ˋ)) {
            ˋˋ = 2;
            dvr.ˊ(ˋ, ʼ, hVar, eVar, bVar, iVar);
        }
    }

    private void ˍ() {
        if (isFinishing()) {
            Logger.ˏ("ThirdAppDownloadActivity", "activity is finishing, can not show loading dialog");
            return;
        }
        if (this.ॱˋ == null) {
            this.ॱˋ = new djl(this);
            this.ॱˋ.setOnCancelListener(new OnCancelListener(this) {
                final /* synthetic */ ThirdAppDownloadActivity ˋ;

                {
                    this.ˋ = r1;
                }

                public void onCancel(DialogInterface dialogInterface) {
                    this.ˋ.ˎˎ();
                }
            });
            this.ॱˋ.setOnKeyListener(new d(this) {
                final /* synthetic */ ThirdAppDownloadActivity ॱ;

                {
                    this.ॱ = r2;
                }

                void ˏ(DialogInterface dialogInterface) {
                    this.ॱ.ˎˎ();
                }
            });
        }
        this.ॱˋ.show();
    }

    private void ˎˎ() {
        Logger.ˏ("ThirdAppDownloadActivity", "loading dialog canceled.");
        this.ʽॱ = true;
        this.ॱˋ.dismiss();
        finish();
    }
}
